import ReadStream from "../utils/ReadStream.js";

function InjectScript({ app }) {
  const script = `
      <script>
      window.process = {
        env: {
          NODE_ENV: "production",
        },
      };

      
    </script>
  `;

  app.use(async (ctx, next) => {
    await next();

    if (ctx.response.is("html")) {
      const html = await ReadStream(ctx.body);
      ctx.body = html.replace(/<head>/, `<head>${script}`);
    }
  });
}

export default InjectScript